package com.haodf.skeleton.anim

import android.animation.ValueAnimator
import android.graphics.Canvas
import android.graphics.Paint
import android.view.animation.LinearInterpolator
import com.haodf.skeleton.SkeletonView

/**
 * @author xiaxiao
 * @date 2023/5/10.
 * 若隐若现-整体透明度渐变
 */
class RuoYinRuoXianLoadingAnimtor(val skeletonView: SkeletonView) : LoadingAnimator() {
    private var mPaint: Paint? = null

    override fun setPaint(p: Paint) {
        mPaint = p
    }

    override fun drawFrame(canvas: Canvas) {
        //
    }

    override fun onInit() {
        //
    }

    override fun createAnim(): ValueAnimator {
        var prior = 0
        val anim = ValueAnimator.ofInt(80, 250)//200
        anim?.interpolator = LinearInterpolator()
        anim?.repeatMode = ValueAnimator.REVERSE

        anim?.repeatCount = ValueAnimator.INFINITE
        anim?.addUpdateListener {
            if ((it.animatedValue as Int) != prior) {
                prior = it.animatedValue as Int
                mPaint?.alpha = prior
                skeletonView.invalidate()
            }
        }
        anim?.duration = 800
        return anim
    }

}